<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
		"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<title>商品选择</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0"><!-- 确保适当的绘制和触屏缩放 -->
	<link rel="stylesheet" href="{$url_css}bootstrap.min.css" type="text/css">
	<link rel="stylesheet" href="{$url_css}admin.css" type="text/css">

	<script type="text/javascript" src="{$url_js}jquery-2.2.0.min.js"></script>
	<script type="text/javascript" src="{$url_js}bootstrap.min.js"></script>
	<script type="text/javascript" src="{$url_js}layer/layer.js"></script>

</head>
<body>

<div class="container" style="width:96%">
		<input type="hidden" id="urltype" value="{$urltype}"/>
		<input type="hidden" id="type" value=""/>
		<table class="table table-bordered table-striped" align="center">
			<tr>
				<td align="center">
					<select class="form-control" style="width: 150px;" name="itmetype"
					        onchange="selectitem(this.value)">
						<option value="">请选择</option>
						{foreach $itemtype as $k => $v}
							<option value="{$k}">{$v}</option>
						{/foreach}
					</select>
				</td>
			</tr>
		</table>
		<table class="table table-bordered table-striped table-hover" align="center">
			<tr>
				<td align="center">商品名称</td>
				<td align="center">原价</td>
				<td align="center">折扣价</td>
				<td align="center">商品图</td>
				<td align="center">操作</td>
			</tr>
			<tbody id="items">

			</tbody>
		</table>

		<table class="table table-bordered table-striped" align="center">
			<tr>
				<td colspan="7" align="right">
					<div class="p_r" id="p_r"></div>
				</td>
			</tr>
		</table>
</div>
<div>&nbsp;</div>

{literal}
	<script>
        $('#p_r').on('click','a', function (){
            var itemtype = $("#type").attr("value");
            var page = this.innerText;
            selectitem(itemtype,page);
            return false;
        });


        function addId(id){
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            var urltype = $("#urltype").val();
            var imgurl = parent.$("#imgurl");
            var imgurl2 = parent.$("#imgurl2");
            if(urltype == 1){
                imgurl.removeAttr("value");
                imgurl.val("qbmeite://app/openGoodsDetail?itemId="+id);
            }
            if(urltype == 2){
                imgurl2.removeAttr("value");
                imgurl2.val("qbmeite://app/openGoodsDetail?itemId="+id);
            }
            parent.layer.close(index); //再执行关闭
        }

        function selectitem(itemtype,page) {
            if(itemtype == ''){
                $("#items tr").remove();
                $("#p_r *").remove();
                return false;
            }
            $.ajax({
                url: 'Ecommerce.php?do=SearchItem',
                type: 'get',
                data: {'itemtype': itemtype,'page':page},
                dataType: 'json',
                success: function (rel) {
                    if (rel.type == 'yes') {
                        if(rel.pagination){
                            $("#p_r").html(rel.pagination);
                        }
                        $("#type").attr("value",rel.k);

                        $("#items tr").remove();
                        $.each(rel.data,function(i,item){
                            var itemid = item.ItemId,
	                            itemtitle = item.Title,
	                            itemRe = item.ReservePrice,
	                            itemZK = item.ZkFinalPrice,
                                PictUrl = item.PictUrl;
                            if (!itemid) {
                                itemid = item._id;
                            }
                            if(!itemRe){
                                itemRe = item.OrigPrice;
                            }
                            if(!itemZK){
                                itemZK = item.ActPrice;
                            }
                            if(!PictUrl){
                                PictUrl = item.PicUrlForWL;
                                if(!PictUrl){
                                    PictUrl = item.PicUrl;
                                }
                            }
                            $("#items").append( "<tr>" +
						                            "<td>"+itemtitle+"</td>" +
						                            "<td>"+itemRe+"</td>" +
                                                    "<td>"+itemZK+"</td>" +
                                                    "<td><img style='width: 100px;height: 120px' src="+PictUrl+"></img></td>" +
                                                    "<td><a class='btn btn-info' onclick='addId("+itemid+")'>添加URL</a></td>" +
					                            "</tr>");
                        });

                    }
                }
            });
        }

	</script>
{/literal}

</body>
<html>